package noodconf

import (
	"encoding/json"
	"github.com/tidwall/gjson"
	"os"
)

var confByte []byte

func NewConf() {
	file, _ := os.Open("./conf.json")
	defer file.Close()
	decoder := json.NewDecoder(file)
	var conf = map[string]interface{}{}
	err := decoder.Decode(&conf)
	if err != nil {
		panic("配置信息加载失败")
	}
	confByte, err = json.Marshal(conf)
	if err != nil {
		panic("配置信息编码失败")
	}
}

// key: "aa.bb.cc"
func Get(key string) gjson.Result {
	return gjson.GetBytes(confByte, key)
}

// key: "aa.bb.cc"
func GetToStr(key string) string {
	return gjson.GetBytes(confByte, key).String()
}
